#include "Test.Batch.h"

#undef  APP_NAME
#define APP_NAME	TestMotion
#undef  APP_BASE
#define APP_BASE	TestBatch


class APP_NAME : public APP_BASE
{
private:
	vec2	pos;
	bool	circle;


public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType ), circle(true)
	{}

	void Update (float dt) override
	{
		TestApp::Update( dt );

		ViewportPtr	vp = ESS()->GetGraphicsEngine()->GetViewport();

		vp->Apply();
		ESS()->GetGLStateManager()->ClearColor( color4f( 0.0f ) );
		
		const int id = 0;

		if ( ESS()->GetInput()->GetTouch(id).InMotion() )
		{
			pos = vp->PositionToNormalized( ESS()->GetInput()->GetTouch(id).pos );
		}
		/*
		if ( ESS()->GetInput()->GetTouch(id).IsPressed() )
		{
			pos += vp->DeltaToNormalized( ESS()->GetInput()->GetTouch(id).delta );
		}*/

		if ( ESS()->GetInput()->IsKeyClicked( EKey::C ) )
			circle = not circle;

		//vec2 const	size = vec2( 0.1f, 0.1f ) * vp->GetResCorrectAspect();

		/*batch.AddBatch( material, Rect2D( rect( pos.x - size.x, pos.y - size.y,
												pos.x + size.x, pos.y + size.y ),
										  rect(), color4u(255) ) );*/

		//ESS()->GetGraphicsEngine()->GetRender2D().DrawCircle( material, pos, 0.1f, 12, color4u(255), false );
		//ESS()->GetGraphicsEngine()->GetRender2D().DrawQuad( material, pos, 0.1f, color4u(255), false );
		
		if ( circle )
			ESS()->GetGraphicsEngine()->GetRender2D().DrawCircle( material, pos, 0.1f, 12, color4u(255), false );
		else
			ESS()->GetGraphicsEngine()->GetRender2D().DrawQuad( material, pos, 0.2f, color4u(255), true );

		batch.Flush();
		batch.Clear();
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}
	
	void OnEnter () override
	{
		APP_BASE::OnEnter();
		
		material.SetColorState( RenderState::ColorState() );
	}
};